#pragma once

#include "hashTable.h"

namespace xyx
{
	template<class K, class V>
	class Unordered_Map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<const K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
						//告诉编译器，这是类型
		typedef typename hash_bucket::HashTable<K, pair<const K, V>, MapKeyOfT>::iterator iterator;
		typedef typename hash_bucket::HashTable<K, pair<const K, V>, MapKeyOfT>::const_iterator const_iterator;

		iterator begin()
		{
			return _table.begin();
		}

		iterator end()
		{
			return _table.end();
		}

		const_iterator begin() const
		{
			return _table.begin();
		}

		const_iterator end() const
		{
			return _table.end();
		}

		pair<iterator, bool> insert(const pair<K, V>& kv)
		{
			return _table.insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = _table.insert(make_pair(key, V()));
			return ret.first->second;
		}

	private:
		hash_bucket::HashTable<K, pair<const K, V>, MapKeyOfT> _table;
	};
}
